﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace 酒店管理
{
    public partial class 选择客人 : Form
    {
        string curRoom;
        //string cust1,cust2,cust3,cust4;
        DataSet tmpDS;
        database tmpDB;
        private string destCust;

        public 选择客人(string RoomID, ref DataSet DS, ref database DB,string sharenum)//传进来要进行选择的房间，传出选择出的客人号
        {
            InitializeComponent();
            curRoom = RoomID;
            tmpDB = DB;
            tmpDS = DS;
            tmpDB.SelectCMD("select 客户姓名,客户证件号 from 登记入住 where 房号='" + curRoom + "' and 预订标记=0", ref tmpDS);
            DataTable tmpdt = tmpDS.Tables["Buffer"];
            radioButton1.Text = tmpdt.Rows[0][0].ToString() + tmpdt.Rows[0][1].ToString();//填充存在的客户名和证件号作为辨认
            radioButton2.Text = tmpdt.Rows[1][0].ToString() + tmpdt.Rows[1][1].ToString();
            
            radioButton1.Tag = tmpdt.Rows[0][0].ToString();//保存对应ID
            radioButton2.Tag = tmpdt.Rows[1][0].ToString();

            radioButton3.Visible = false;//先隐藏,3,4选项
            radioButton4.Visible = false;

            if (sharenum == "2")//如果有3个客户合住
            {
                radioButton3.Text = tmpdt.Rows[2][0].ToString() + tmpdt.Rows[2][1].ToString();
                radioButton3.Tag = tmpdt.Rows[2][0].ToString();
                radioButton3.Visible = true;
            }
            if (sharenum == "3")//如果有4个客户合住
            {
                radioButton3.Text = tmpdt.Rows[2][0].ToString() + tmpdt.Rows[2][1].ToString();
                radioButton3.Tag = tmpdt.Rows[2][0].ToString();
                radioButton4.Text = tmpdt.Rows[3][0].ToString() + tmpdt.Rows[3][1].ToString();
                radioButton4.Tag = tmpdt.Rows[3][0].ToString();
                radioButton3.Visible = true;
                radioButton4.Visible = true;
            }
            radioButton1.Checked = true;//预选第一项防止返回空
        }

        public string returnsCust()
        {
            string custID = destCust;
            return custID;
        }

        private void GetSelectCust()
        {
            if (radioButton1.Checked == true) destCust = radioButton1.Tag.ToString();
            else if (radioButton2.Checked == true) destCust = radioButton2.Tag.ToString();
            else if (radioButton3.Checked == true) destCust = radioButton3.Tag.ToString();
            else if (radioButton4.Checked == true) destCust = radioButton4.Tag.ToString();
        }

        private void radioButton1_CheckedChanged(object sender, EventArgs e)
        {
            GetSelectCust();
        }

        private void radioButton2_CheckedChanged(object sender, EventArgs e)
        {
            GetSelectCust();
        }

        private void radioButton3_CheckedChanged(object sender, EventArgs e)
        {
            GetSelectCust();
        }

        private void radioButton4_CheckedChanged(object sender, EventArgs e)
        {
            GetSelectCust();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
        }

    }
}